/* drivers/leds/leds-s3c24xx.c
 *
 * (c) 2006 Simtec Electronics
 *	http://armlinux.simtec.co.uk/
 *	Ben Dooks <ben@simtec.co.uk>
 *
 * s5pv210 - LEDs GPIO driver
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
*/

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/leds.h>
#include <linux/gpio.h>
#include <linux/slab.h>   // kzalloc 函数库

#include <linux/platform_device.h> // platform_driver
#include <linux/module.h>
#include <linux/ioport.h>

/***
 *   编译 insmod 以后  /sys/bus/platform/devices/my_platform_device 生成这个目录
 */

#define MEM_START_ADDR 0xFDD60000   //这个地址是led灯的地址
#define MEM_END_ADDR   0xFDD60004
#define IRQ_NUMBER     101


/** 
 1. 定义：my_platform_device

 2. 注册：platform_device_register
 * 
 */

static struct resource my_resources[] = {
   [0]= {
        .start = MEM_START_ADDR,    // 内存资源起始地址
        .end = MEM_END_ADDR,        // 内存资源结束地址
        .flags = IORESOURCE_MEM,    // 标记为内存资源
        .name ="reg",
    },
   [1] ={
        .start = IRQ_NUMBER,        // 中断资源号
        .end = IRQ_NUMBER,          // 中断资源号
        .flags = IORESOURCE_IRQ,    // 标记为中断资源
        .name="irq",
    },
};
 
static void my_platform_device_release(struct device *dev)
{
    	printk(KERN_INFO "This is my_platform_device_release  \n");
};


static struct platform_device my_platform_device = {
    .name = "my_platform_device",                  // 设备名称
    .id = -1,                                      // 设备ID
    .num_resources = ARRAY_SIZE(my_resources),     // 资源数量
    .resource = my_resources,                      // 资源数组
    .dev = {
      .release = my_platform_device_release,     // 释放资源的回调函数，是dev结构体的函数指针
    }
};



static int __init rk3568_device_init(void)
{

  printk(KERN_INFO "This is rk3568_device_init  \n");
	return platform_device_register(&my_platform_device);
}

static void __exit rk3568_device_exit(void)
{
    printk(KERN_INFO "This is rk3568_device_exit  \n");
  	platform_device_unregister(&my_platform_device);
}



module_init(rk3568_device_init);
module_exit(rk3568_device_exit);

MODULE_AUTHOR("tony <tony.deng321@gmail.com>");
MODULE_DESCRIPTION("X210 LED driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("s5pv210-led");
